<?php
// +----------------------------------------------------------------------
// | Genadmin [ Genadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: sai <1430792918@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\model\system;

use app\admin\logic\system\SystemConfigLogic;
use app\basic\BaseModel;
/**
 * 附件模型
 * Class SystemUploadfile
 * @package app\model
 */
class SystemUploadfile extends BaseModel
{
    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';

    protected $table = 'eb_system_uploadfile';

    public function searchOriginNameAttr($query, $value)
    {
        $query->where('origin_name', 'like', '%'.$value.'%');
    }

    public function searchMimeTypeAttr($query, $value)
    {
        $query->where('mime_type', 'like', $value.'/%');
    }


    /**
     * 补全URL链接
     */
    public function getUrlAttr($value)
    {
        $storage = (new SystemConfigLogic())->getConfig("storage")['value'];
        if(!empty($storage['engine'][$this['storage_mode']]['config'])){
            return $storage['engine'][$this['storage_mode']]['config']['domain']."/".$value;
        }
        return "//" .request()->host(true) .$value;
    }

}